package visualization.graphkeymodel.piechart;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import visualization.components.GraphSprite;


/**
 * One slice of a pie graph
 * 
 * @author Ben Schwab
 * 
 */
public class PieSlice extends GraphSprite {

    private static final int STROKE_WIDTH = 10;
    private double myValue;
    private Color myColor;

    /**
     * 
     * @param title the title of the slice
     * @param value the weight of the slice
     * @param color color of the slice
     * @param drawArea rectangle area to draw slice
     */
    public PieSlice (String title, double value, Color color, Rectangle drawArea) {
        super(drawArea);
        myValue = value;
        myColor = color;
    }

    /**
     * 
     * @param pen current visualization pen
     * @param startAngle start angle for pie slice in degrees
     * @param endAngle end angle of pie slice in degrees
     */
    public void paint (Graphics2D pen, double startAngle, double endAngle) {
        Rectangle drawArea = getDrawArea();
        pen.setColor(myColor);
        pen.fillArc((int) drawArea.getMinX(), (int) drawArea.getMinY(), (int) drawArea.getWidth(),
                    (int) drawArea.getWidth(), (int) startAngle, (int) endAngle);
        pen.setColor(Color.BLACK);
        BasicStroke s = new BasicStroke(STROKE_WIDTH);
        pen.setStroke(s);
        pen.drawArc((int) drawArea.getMinX(), (int) drawArea.getMinY(), (int) drawArea.getWidth(),
                    (int) drawArea.getWidth(), (int) startAngle, (int) endAngle);

    }

    /**
     * 
     * @return returns the value of the slice
     */
    public double getValue () {
        return myValue;
    }

    @Override
    public void paint (Graphics2D pen) {
        paint(pen, 0, 0);

    }

}
